<template>
  <el-card shadow="hover" style="height: 100%;" :body-style="{height:'100%'}">
    <template #header>
      File 转base64
    </template>

    <input type="file" ref="input">
  </el-card>
</template>

<script setup lang="ts" name="fileToBase64">
const input = ref<HTMLInputElement>()

onMounted(() => {
  input.value.addEventListener('change',(e:any) => {
    //把File读取成base64
    const fileReader = new FileReader()
    fileReader.readAsDataURL(e.target.files[0])
    fileReader.onload = e => {
      const base64 = e.target.result
      console.log(base64)
    }
  })
})
</script>

<style scoped lang="less">

</style>
